#include "json_private.h"

void check(string &ans, char c)
{
    if (c == ' ' || c == '\t' || c == '\n')
    {
        return;
    }
    else
    {
        ans += c;
    }
}

string rms(const string &nums)
{
    string ans = "";
    int size = nums.size();
    for (int i = 0; i < size; i++)
    {
        if (nums[i] == '\"')
        {
            ans += nums[i];
            i++;
            while (nums[i] != '\"' && i < size)
            {
                ans += nums[i];
                i++;
            }
            ans += nums[i];
            i++;
        }
        if (i < size - 1 && nums.substr(i, 2) == "//")
        {
            return ans;
        }
        check(ans, nums[i]);
    }

    return ans;
}

string getName(const string &in, int start, int *rei)
{
    int size = in.size();
    string name = "";
    for (int i = start; i < size; i++)
    {
        if (in[i] == '\"')
        {
            *rei = i + 1;
            return name;
        }
        name += in[i];
    }
    return "";
}

string nts(long double nums, int pcs)
{
    if (nums == 0)
    {
        return "0";
    }
    string ans = "";
    if (nums >= 1)
    {
        long long temp = nums;
        while (temp > 0)
        {
            ans = char(temp % 10 + '0') + ans;
            temp /= 10;
        }
    }
    else
    {
        ans = '0';
    }
    if ((long long)nums == nums)
    {
        return ans;
    }
    else
    {
        ans += '.';

        while (nums > 0 && pcs > 0)
        {
            nums = nums - (long long)nums;
            nums *= 10;
            ans += char((long long)nums % 10 + '0');
            pcs--;
        }
    }
    return ans;
}